package org.carabiner.examples;

import java.awt.Component;
import java.util.Iterator;
import java.util.List;

import org.carabiner.Carabiner;
import org.carabiner.infopanel.CarabinerMessage;
import org.carabiner.infopanel.Inspector;
import org.jmock.MockObjectTestCase;

public class TestInspectorExample extends MockObjectTestCase
{
  private InspectorExample inspectorExample = null;

  protected void setUp() throws Exception
  {
    super.setUp();
    inspectorExample = new InspectorExample();
  }

  protected void tearDown() throws Exception
  {
    inspectorExample = null;
    super.tearDown();
  }

  protected Component getComponent()
  {
    return inspectorExample;
  }

  /**
   * This test demonstrates how to use the inspector to programmaticly check
   * that your GUI control meets a set of defined rules.
   * 
   */
  public void testProgrammaticInspection()
  {
    Inspector inspector = new Inspector(inspectorExample);
    List warningList = inspector.inspect();
    StringBuffer rules = new StringBuffer();
    rules.append("[");
    for (Iterator i = warningList.iterator(); i.hasNext();)
    {
      CarabinerMessage warning = (CarabinerMessage) i.next();
      rules.append(warning.getName() + ":" + warning.getComponentName() + ", ");
    }
    rules.append("]");
    assertEquals("Rules violated: " + rules.toString(), 0, warningList.size());
  }

  public static void main(String[] args) throws Exception
  {
    TestInspectorExample test = new TestInspectorExample();
    test.setUp();
    Carabiner.showHarness(test.inspectorExample);
  }
}
